<template>
  <div class="document-manager-wapper">
    <van-nav-bar
      title="单据列表"
      left-text="返回"
      left-arrow
      fixed
      @click-left="goback"
      @click-right="onClickLeft"
    >
      <van-icon name="arrow-left" slot="left" />
      <van-icon name="search" slot="right" />
    </van-nav-bar>
    <div class="document-content">
      <van-pull-refresh
        v-model="isLoading"
        success-text="刷新成功"
        @refresh="onRefresh"
      >
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
          <div
            class="cell-content"
            @click="showInfo(item.billid)"
            v-for="(item, index) in list"
            :key="index"
          >
            <!-- 使用 title 插槽来自定义标题 -->

            <div class="custom-title">单据编码:{{ item.billid }}</div>

            <div class="custom-title1">
              <span class="user-line-input"
                >劳务队名称:{{item.issuecoid}}</span
              >
              <span class="user-line-label">
                <van-button type="primary" size="mini"
                  >单据状态:{{ item.statusDes }}</van-button
                >
              </span>
            </div>
            <div class="custom-title1">
              <span class="user-line-input">地点:{{item.issuesiteid}}</span>
              <span class="user-line-label">制单人:{{ item.username }}</span>
            </div>
          </div>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>

<script>
import { getInvbillmstrs ,getIInvbillmstrs} from "@/api/Invbillmstr.js";
import { Toast } from "vant";
export default {
  name: "DocumentManager",
  data() {
    return {
      list: [],
      isLoading: false,
      loading: false,
      finished: false,
      pageInfo: {
        page: 0,
        pageSize: 20
      }
    };
  },
  methods: {
    goback() {
      this.$router.back(-1);
    },
    onClickLeft() {
      console.log("onClickLeft");
      // this.$router.back(-1);
      this.$router.push({
        path: "/documentsearch",
        query:{
          status:"I"
        }
      });
    },
    getInvbillmstrsList(flag) {
      var that = this;
      getIInvbillmstrs(this.pageInfo).then(res => {
        // console.info(res.data[1]);
        that.loading = false;
        if (res.data && res.data.length) {
          this.list = this.list.concat(res.data);
        } else {
          that.finished = true;
        }
        if (flag) {
          Toast("刷新成功");
          this.isLoading = false;
        }
      });
    },
    showInfo(id) {
      this.$router.push({
        path: "/items/info/out",
        query: { id: id }
      });
    },
    onLoad() {
      this.pageInfo.page += 1;
      this.pageInfo.billid = this.$route.query.billid;
      this.pageInfo.empid = this.$route.query.empid;
      this.pageInfo.recvsiteid = this.$route.query.recvsiteid;
      this.pageInfo.itemid = this.$route.query.itemid;
      this.pageInfo.itemDesc = this.$route.query.itemDesc;
      this.pageInfo.itemSpec = this.$route.query.itemSpec;
      this.pageInfo.comptype = this.$route.query.comptype;
      this.pageInfo.issuecoid = this.$route.query.issuecoid;
      this.pageInfo.sitearea=this.$route.query.sitearea;
      this.pageInfo.compiler = this.$route.query.compiler;

      if(this.$route.query.status!=null){
        this.pageInfo.billid = this.$route.query.status;
      }
	  this.getInvbillmstrsList();
      /* setTimeout(() => {
                    for (let i = 0; i < 10; i++) {
                        this.list.push(this.list.length + 1);
                    }
                    // 加载状态结束
                    this.loading = false;

                    // 数据全部加载完成
                    if (this.list.length >= 30) {
                        this.finished = true;
                    }
                }, 2000); */
    },
    filters: {
      filterStatusType: function(val) {
        switch (val) {
          case "G":
            return "审批";

          case "P":
            return "过账";

          case "K":
            return "确认";

          case "C":
            return "";
          default:
            return "";
        }
      },
      timestampToTime(cjsj) {
        var date = new Date(cjsj); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + "-";
        var M =
                (date.getMonth() + 1 < 10
                        ? "0" + (date.getMonth() + 1)
                        : date.getMonth() + 1) + "-";
        var D = date.getDate() + " ";
        var h = date.getHours() + ":";
        var m = date.getMinutes() + ":";
        var s = date.getSeconds();
        return Y + M + D + h + m + s;
      }
    },
    onRefresh() {
      this.pageInfo.page = 1;
      this.list = [];
      this.getInvbillmstrsList(true);
    }
  }
};
</script>

<style scoped lang="scss">
.document-manager-wapper {
  position: relative;
  .document-content {
    position: relative;
    top: 46px;
    height: calc(100%);
    /*margin-bottom: 10px;*/
    overflow-y: auto;
    .cell-content {
      padding: 5px 10px;
      background: #fff;
      border-bottom: solid 1px #ddd;
    }
    .custom-title {
      color: #000;
      padding: 0px 0px 5px 0px;
      font-weight: bold;
    }
    .custom-title1 {
      color: #000;
      padding: 0px 0px 5px 0px;
      span {
        font-size: 12px;
      }
    }
    .user-line-label {
      width: 120px;
      text-align: right;
      font-size: 14px;
      color: #606266;
      line-height: 1;
      /*padding: 0px 12px 10px 0;*/
      box-sizing: border-box;
      display: inline-block;
    }
    .user-line-input {
      position: relative;
      display: inline-block;
      font-size: 14px;
      vertical-align: top;
      width: calc(100% - 120px);
    }
  }
}
</style>
